*===============================================================================
*=== FILE 9 --- TRANSACTION REGRESSIONS
*===============================================================================
clear all
set more off

cap cd ""


cap log close
log using "replication output/regressions_transaction", replace

use "replication output/transaction_regression_data", clear

* Create interactions

gen ln_index_zipcode_year       = ln(index_zipcode_year + 0.01)
gen ln_index_zipcode_year_uw6ft = uw6ft * ln_index_zipcode_year

gen ln_index_zipcode_quarter       = ln(index_zipcode_quarter + 0.01)
gen ln_index_zipcode_quarter_uw6ft = uw6ft * ln_index_zipcode_quarter

gen index_zipcode_year_uw6ft    = uw6ft * index_zipcode_year
gen index_zipcode_quarter_uw6ft = uw6ft * index_zipcode_quarter

* Label
label variable ln_index_zipcode_year    "ln(Index by Zip-Year)"
label variable ln_index_zipcode_quarter "ln(Index by Zip-Quarter)"

label variable ln_index_zipcode_year_uw6ft    "Flood Zone x ln(Index by Zip-Year)"
label variable ln_index_zipcode_quarter_uw6ft "Flood Zone x ln(Index by Zip-Quarter)"

label variable index_zipcode_year    "Index by Zip-Year"
label variable index_zipcode_quarter "Index by Zip-Quarter"

label variable index_zipcode_year_uw6ft    "Flood Zone x Index by Zip-Year"
label variable index_zipcode_quarter_uw6ft "Flood Zone x Index by Zip-Quarter"

label variable ln_transaction_price "ln(Transaction Price)"
label variable uw6ft                "Flood Zone"


eststo: reghdfe ln_transaction_price uw6ft ln_index_zipcode_year_uw6ft   , absorb(apt3 finishedsquarefeet_pct lotsizesquarefeet_pct prop_age_group remodel_age_group bedroomcnt bathroomcnt zip_quarter_fe) vce(cluster zip_quarter)
eststo: reghdfe ln_transaction_price uw6ft ln_index_zipcode_quarter_uw6ft, absorb(apt3 finishedsquarefeet_pct lotsizesquarefeet_pct prop_age_group remodel_age_group bedroomcnt bathroomcnt zip_quarter_fe) vce(cluster zip_quarter)
eststo: reghdfe ln_transaction_price uw6ft ln_index_zipcode_year_uw6ft   , absorb(propertyid zip_quarter_fe) vce(cluster zip_quarter)
eststo: reghdfe ln_transaction_price uw6ft ln_index_zipcode_quarter_uw6ft, absorb(propertyid zip_quarter_fe) vce(cluster zip_quarter)
eststo: reghdfe ln_transaction_price uw6ft index_zipcode_year_uw6ft      , absorb(apt3 finishedsquarefeet_pct lotsizesquarefeet_pct prop_age_group remodel_age_group bedroomcnt bathroomcnt zip_quarter_fe) vce(cluster zip_quarter)
eststo: reghdfe ln_transaction_price uw6ft index_zipcode_year_uw6ft      , absorb(propertyid zip_quarter_fe) vce(cluster zip_quarter)
eststo: reghdfe ln_transaction_price uw6ft index_zipcode_quarter_uw6ft   , absorb(apt3 finishedsquarefeet_pct lotsizesquarefeet_pct prop_age_group remodel_age_group bedroomcnt bathroomcnt zip_quarter_fe) vce(cluster zip_quarter)
eststo: reghdfe ln_transaction_price uw6ft index_zipcode_quarter_uw6ft   , absorb(propertyid zip_quarter_fe) vce(cluster zip_quarter)


* Now for coefficients
tostring bathroomcnt, gen(br_str) format(%4.1f)
encode br_str, gen(br)
eststo: reghdfe ln_transaction_price uw6ft ln_index_zipcode_year_uw6ft i.apt3 i.finishedsquarefeet_pct i.lotsizesquarefeet_pct ///
										   i.prop_age_group i.remodel_age_group i.bedroomcnt i.br, ///
									       absorb(zip_quarter_fe) vce(cluster zip_quarter)
cap log close
										  